package com.example.Utils;



import com.alibaba.fastjson.JSON;
import com.example.pojo.Course;
import com.example.pojo.ParseStudent;
import com.example.pojo.ParseTeacher;
import com.formdev.flatlaf.json.Json;
import com.google.gson.JsonArray;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Vector;


public class ResultUtil {
    public static String ResultLoginParse(String result){
        JSONObject jsonObject=JSONObject.fromObject(result);
        String code= jsonObject.getString("code");
        if(code.equals("0")){
            return "ERROR";
        }else
        if (code.equals("1")){
            String date= jsonObject.getString("data");
            JSONObject datejson=JSONObject.fromObject(date);
            return datejson.getString("authority");
        }
        return null;
    }

    public static String ResultParse(String result) {
        JSONObject jsonObject = JSONObject.fromObject(result);
        String code = jsonObject.getString("code");
        return code;
    }

    public static Vector<ParseStudent> ResultVectorStudent(String reult){
        JSONObject jsonObject=JSONObject.fromObject(reult);
        String datas=jsonObject.getString("data");
        Vector<Vector> students=new Vector<>();
        ArrayList<ParseStudent> arrayList = (ArrayList<ParseStudent>) JSON.parseArray(datas,ParseStudent.class);
        Vector<ParseStudent> parseStudents=new Vector<>(arrayList);
        return parseStudents;
    }

    public static Vector<ParseTeacher> ResultVectorTeacher(String reult){
        JSONObject jsonObject=JSONObject.fromObject(reult);
        String datas=jsonObject.getString("data");
        Vector<Vector> students=new Vector<>();
        ArrayList<ParseTeacher> arrayList = (ArrayList<ParseTeacher>) JSON.parseArray(datas,ParseTeacher.class);
        Vector<ParseTeacher> parseTeachers=new Vector<>(arrayList);
        return parseTeachers;
    }

    public static Vector<Course> ResultVectorCourse(String reult){
        JSONObject jsonObject=JSONObject.fromObject(reult);
        String datas=jsonObject.getString("data");
        Vector<Vector> couses=new Vector<>();
        ArrayList<Course> arrayList = (ArrayList<Course>) JSON.parseArray(datas,Course.class);
        Vector<Course> courses=new Vector<>(arrayList);
        return courses;
    }

    public static String[] ResultVectorTeachers(String reult){
        JSONObject jsonObject=JSONObject.fromObject(reult);
        String datas=jsonObject.getString("data");
        ArrayList<String> teachers = (ArrayList<String>) JSON.parseArray(datas,String.class);
        String[] strings=teachers.toArray(new String[teachers.size()]);
        return strings;
    }

}
